package utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.utils.getDefinitionByName;

	/**
	 * 初始化实例工具类
	 */	
	public class Initialization
	{
		
		/**
		 * 初始化实例
		 * @param instance
		 * @param parent
		 * @param initObject
		 */		
		public static function init(instance:Object, parent:DisplayObjectContainer = null, initObject:Object=null):*
		{
			if(instance == null) return null;
			
			for(var property:String in initObject) {
				try {
					instance[property] = initObject[property];
				}catch(error:Error) {
					trace(error);
				}
			}
			
			if(parent != null && instance is DisplayObject) parent.addChild(instance as DisplayObject);
			
			return instance;
		}
		//
	}
}